<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico">
<title>待办事务清单 - MyWebSpace</title>
<style>
a,a:hover{text-decoration:none;color:#000;}
.denglu input{border:none; border-bottom:solid 1px #F05046; padding:10px;}
.shiwus{margin-top: 50px;}
.shiwu{
	text-align:left;
	font-size:12px;
	line-height:36px;
	color:#000;
	border:1px #FFF solid;
	min-width:300px;}
.shiwu:hover{background-color:#FF9;}
.ksriqi,.jsriqi{color:#999;}
.blue{background-color:#CFF;}
.green{background-color:#CFC;color: #F05046;}
.jindu{color:#666;}
.lishijilv,.gengxin{ background-color:#CFC;color:#666;}
.gengxin input{border: 0px;border-bottom: #000 solid 1px;background-color: #CFC;}
.caidan{line-height: 38px;
	background-color:#CCC; padding: 0 5px;
	position:fixed;/*固定作用*/
	top:0px;
	right:5px;
	z-index:999;
	text-align:right;}
.caidan input{line-height: 28px;border: 1px #000 solid;}
.caidan button{line-height: 36px;border: none;}
.caidan button:hover{ background-color: #CFC;}
</style>
</head>
<body><?php
$mima="123456"; //自定义登陆密码
$zerenren="默认责任人";//默认责任人
$redir="index.php?x=".@$_GET["x"]."&t=".@$_GET["t"]."&sid=".@$_GET["sid"]."#".@$_POST["sid"];	//'跳转地址
session_start();
if (@$_GET['r']=="denglu" && @$_POST['denglu']==$mima) {	//验证登陆
	$_SESSION['tyadmin']="tyadmin";
	echo "登陆成功！";
}elseif (@$_GET['r']=="tuichu"){
	session_destroy();
	echo "已退出！";
	exit;
}elseif (!@$_SESSION['tyadmin']=="tyadmin"){
	echo "<div class=denglu><form action=?r=denglu method=post><input type=password name=denglu> <input type=submit value='登陆'></form></div>";
	exit;
} ?>

<div class="shiwus"><?php 
  class conMyDB extends SQLite3
 {
	function __construct()
	{
	   $this->open('shiwusqlite.db');//请修改数据库的地址和名字
	}
 }
 $ConSQLite = new conMyDB(); //连接数据库文件，如无则创建空文件
 if(!$ConSQLite){
	echo $ConSQLite->lastErrorMsg();
 }

if (!@empty($_GET["x"])){
	$sql="select * from shiwu where jsriqi is NULL ORDER BY sid desc";	//'仅显示未完成SQL
}else{
	$sql="select * from shiwu order by sid desc limit 100 ";	//'显示最近100	
}
$ret = $ConSQLite->query($sql);
while($row = $ret->fetchArray(SQLITE3_ASSOC) ){	
	echo "<div id='".$row['sid']."' class='shiwu ";	//div.a开始
		if (!$row['jsriqi']){	echo " blue";}	
		if ($row['sid']==@$_GET["sid"]){ echo " green";}
	echo "'>";
	echo "<a href='index.php?t=rizhi&x=".@$_GET["x"]."&sid=".$row['sid']."#".$row['sid']."'><div class=shiwubiaoti>";	//a开始
	echo "<span class=ksriqi>".$row['ksriqi']."</span>
		<span class=zerenren>&lt;".$row['zerenren']."&gt;</span>
		<span class=neirong>".$row['neirong']."</span>
		<span class=jsriqi>".$row['jsriqi']."</span>
		<span class=jindu>&brvbar;&gt;&gt;";
			$sql2="select * from rizhi where sid=".$row['sid']." order by id desc limit 1";	//显示最近一条跟进日志
			$ret2 = $ConSQLite->query($sql2);
			while($row2 = $ret2->fetchArray(SQLITE3_ASSOC) ){
				echo $row2['neirong'];
			}
	echo "</span></div></a>\n";	//a结束
	if (@$_GET['t']=="rizhi" && $row['sid']==@$_GET['sid']){
		$sql1="select * from rizhi where sid=".$row['sid']." order by id desc ";	//显示选中跟进日志
		$ret1 = $ConSQLite->query($sql1);
		echo "<div class=gengxin>
		<form action='index.php?d=jia&t=rizhi&sid=".@$_GET['sid']."&x=".@$_GET['x']."' method=post>
			更新进度：<input name=neirong type=text autocomplete=off placeholder='如提交则必填' /><input name=sid value=".@$_GET['sid']." readonly style='display: none;' />
			<button type=submit>提 交</button></form>
		<form action='index.php?d=jieshu&t=rizhi&sid=".@$_GET['sid']."&x=".@$_GET['x']."' method=post>
			事务结束：日期<input name=jsriqi value=".date("Y-m-d")." placeholder='注意格式' size=9/>
			<input name=sid value=".@$_GET['sid']." readonly style='display: none;'/>
			<button type=submit>结 束</button></form>
		<form action='index.php?d=zerenren&t=rizhi&sid=".@$_GET['sid']."&x=".@$_GET['x']."' method=post>
			变更责任人：<input name=zerenren type=text  placeholder='如变更则必填' />
			<input name=sid value=".@$_GET['sid']." readonly style='display: none;' />
			<button type=submit>变 更</button></form>
		</div>\n";
		while($row1 = $ret1->fetchArray(SQLITE3_ASSOC) ){
			echo "<div class=lishijilv>&gt;&gt;".$row1['shijian']."&nbsp;&nbsp;&nbsp;".$row1['neirong']."</div>\n";
		}
	}

	echo "</div>\n";	//div.a 结束
}


?></div>
<?php //写入SQL
if (@$_GET['t']=="jia" && @$_GET['d']=="jia"){	//添加新事务
	if (!@empty($_POST["neirong"])&&!@empty($_POST["zerenren"])&&!@empty($_POST["ksriqi"])){ //新事务标题内容、责任人、开始日期都不能为空
		$sql ="INSERT INTO shiwu (neirong,zerenren,ksriqi)
			VALUES ('$_POST[neirong]','$_POST[zerenren]','$_POST[ksriqi]')";	
		$ConSQLite->exec($sql);
	}else{
		echo "<script type=text/javascript>alert('新事务标题内容、责任人、开始日期都不能为空');</script>";
	}
	echo "<meta http-equiv=refresh content=0;url=".$redir.">";
	exit;
}elseif (@$_GET['t']=="rizhi" && !@empty($_POST["sid"])){	//事务进度跟进
	if (@$_GET['d']=="jieshu"){	//结束事务
		$sql ="update shiwu set jsriqi='$_POST[jsriqi]' where sid='$_POST[sid]'";	
		$sql1 ="INSERT INTO rizhi (sid,shijian,neirong)
		VALUES ('$_POST[sid]','".date("Y-m-d H:i:s")."','事务结束于$_POST[jsriqi]')";
		$ConSQLite->exec($sql);
		$ConSQLite->exec($sql1);
		echo "<meta http-equiv=refresh content=0;url=".$redir.">";
		exit;
	}elseif (@$_GET['d']=="jia" && !@empty($_POST["neirong"])){	//跟新事务进度//内容不能为空
		$sql ="INSERT INTO rizhi (sid,shijian,neirong)
		VALUES ('$_POST[sid]','".date("Y-m-d H:i:s")."','$_POST[neirong]')";	
		$ConSQLite->exec($sql);
		echo "<meta http-equiv=refresh content=0;url=".$redir.">";
		exit;
	}elseif (@$_GET['d']=="zerenren" && !@empty($_POST["zerenren"])){	//变更责任人
		$sql ="update shiwu set zerenren='$_POST[zerenren]' where sid='$_POST[sid]'";
		$sql1 ="INSERT INTO rizhi (sid,shijian,neirong)
		VALUES ('$_POST[sid]','".date("Y-m-d H:i:s")."','变更责任人：$_POST[zerenren]')";
		$ConSQLite->exec($sql);
		$ConSQLite->exec($sql1);
		echo "<meta http-equiv=refresh content=0;url=".$redir.">";
		exit;
	}
}
?>

<div class="caidan"><a onclick ="showAndHidden()">菜单：添加事务</a>
<div id="xianyin" style="display:none;">
<br>
<a href="index.php?x=less">仅进行中的事务</a>
<br>
<a href="index.php">近100全部事务</a>
<br><br>
<form action="?d=jia&t=jia&sid=<?=@$_GET['sid'] ?>&x=<?=@$_GET['x'] ?>" method="post">
	<div>新事务：<input name="neirong" type="text" autocomplete="off" placeholder="新事务标题描述*必填"></div>
	<div>责任人：<input name="zerenren" type="text" value="<?=$zerenren?>" placeholder="*必填"></div>
	<div>开始日期：<input name="ksriqi" type="text" value="<?=date("Y-m-d") ?>" placeholder="注意日期格式*必填"></div>
	<div><a href="index.php?r=tuichu">退出</a>&nbsp;&nbsp;&nbsp;&nbsp;<button type="submit">新事务-提交</button></div>
</form>
<br>
</div>
</div><?php $ConSQLite->close();	//关闭数据库连接 ?>
<script type="text/javascript">
function showAndHidden(){ //显示或隐藏菜单
  var sad=document.getElementById("xianyin");
  if(sad.style.display=='block') sad.style.display='none';
  else sad.style.display='block';
}
</script>

</body>
</html>